#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int n,m,a;
string s;
map<string,vector<int>> title,author,keyword,publisher,year;

signed main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        getline(cin,s);
        getline(cin,s);
        title[s].push_back(a);
        getline(cin,s);
        author[s].push_back(a);
        getline(cin,s);
        for(int i=0;i<s.size();i++){
            for(int j=i;j<s.size();j++){
                if(s[j]==' '){
                    keyword[s.substr(i,j-i)].push_back(a);
                    i = j;
                    break;
                }
                if(j==s.size()-1){
                    keyword[s.substr(i,j-i+1)].push_back(a);
                    i = j;
                    break;
                }
            }
        }
        keyword[s].push_back(a);
        getline(cin,s);
        publisher[s].push_back(a);
        getline(cin,s);
        year[s].push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++){
        scanf("%d: ",&a);
        getline(cin,s);
        cout<<a<<": "<<s<<"\n";
        if(a==1){
            if(title[s].empty()){
                cout<<"Not Found\n";
                continue;
            }
            sort(title[s].begin(),title[s].end());
            for(int i=0;i<title[s].size();i++)    printf("%07d\n",title[s][i]);
        }
        if(a==2){
            if(author[s].empty()){
                cout<<"Not Found\n";
                continue;
            }
            sort(author[s].begin(),author[s].end());
            for(int i=0;i<author[s].size();i++)    printf("%07d\n",author[s][i]);
        }
        if(a==3){
            if(keyword[s].empty()){
                cout<<"Not Found\n";
                continue;
            }
            sort(keyword[s].begin(),keyword[s].end());
            for(int i=0;i<keyword[s].size();i++)    printf("%07d\n",keyword[s][i]);
        }
        if(a==4){
            if(publisher[s].empty()){
                cout<<"Not Found\n";
                continue;
            }
            sort(publisher[s].begin(),publisher[s].end());
            for(int i=0;i<publisher[s].size();i++)    printf("%07d\n",publisher[s][i]);
        }
        if(a==5){
            if(year[s].empty()){
                cout<<"Not Found\n";
                continue;
            }
            sort(year[s].begin(),year[s].end());
            for(int i=0;i<year[s].size();i++)    printf("%07d\n",year[s][i]);
        }
    }
    return 0;
}
